<?php
namespace app\home\validate;

use think\Validate;
use app\home\validate\Base;

class PayFor extends Base
{
    protected $rule = [
        'money'           => 'require|number|isMoney:money',
        'pay_uid'         => 'require|number|check_shop:pay_uid',
        'type'            => 'in:2,4,6,7,100',
    ];

    protected $message = [
        'money.require'           => '请输入金额',
        'money.number'            => '金额格式错误',
        'money.isMoney'           => '金额格式错误',
        'pay_uid.require'         => '收款商户错误',
        'pay_uid.number'          => '收款商户错误',
        'pay_uid.check_shop'      => '收款商户错误',
        'type.in'                 => '请选择钱包类型',
    ];
    /**
     * 是否商户
     * @param int       $pay_uid     商户id
     * @return bool
     */
    protected function check_shop($pay_uid)
    {
        $rank =  db('user')
                ->where('id',$pay_uid)
                ->value('rank_id');
        if ($rank < 7) {
            return false;
        }else{
            return true;
        }
    }
}